<template>
    <div class="hone-new">
        <HomePanel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
            <template #right>
                <XtxMore></XtxMore>
            </template>
            <div ref="target" style="position: relative;height: 426px;">
                <transition name="fade">
                    <!-- 默认插槽 面板内容 -->
                    <ul v-if="goods.length" class="goods-list">
                        <li v-for="item in goods" :key="item.id">
                            <RouterLink :to="`/product/${item.id}`">
                                <img :src="item.picture" alt="">
                                <p class="name ellipsis">{{ item.name }}</p>
                                <p class="price">&yen;{{ item.price }}</p>
                            </RouterLink>
                        </li>
                    </ul>
                    <!-- 骨架组件 -->
                    <HomeSkeleton v-else bg="#f0f9f4"></HomeSkeleton>
                </transition>
            </div>
        </HomePanel>
    </div>
</template>

<script>
import { ref } from 'vue'
import { findNew } from '@/api/home'
import HomePanel from '@/views/Home/components/home-panel'
import HomeSkeleton from '@/views/Home/components/home-skeleton'
import { useLazyData } from '@/hooks/index' //数据懒加载
export default {
    name: 'HoneNew',
    components: {
        HomePanel,
        HomeSkeleton
    },
    setup() {
        // const goods = ref([])
        //获取DOM元素
        const target = ref(null)
        const goods = useLazyData(target,findNew)
        return {
            goods,
            target
        }
    }
}
</script>

<style lang="less" scoped>


.goods-list {
    display: flex;
    justify-content: space-between;
    height: 406px;

    li {
        width: 306px;
        height: 406px;
        background: #f0f9f4;
        .hoverShadow();

        img {
            width: 306px;
            height: 306px;
        }

        p {
            font-size: 22px;
            padding: 12px 30px 0 30px;
            text-align: center;
        }

        .price {
            color: @priceColor;
        }
    }
}
</style>